package com.qf.listener;

import com.qf.entity.Email;
import com.qf.service.IMailService;
import com.qf.service.IUserService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author：刘亚康
 * @Date：2020/4/7
 * @QQ：50770284
 * @Phone：18235947935
 * @Desc : EmailQueue监听类
 **/
@Component
public class EmailQueueListener {
    //创建线程池
    private ExecutorService service= Executors.newFixedThreadPool(10);

    @Autowired
    private IMailService mailService;

    @RabbitListener(queues = "emailQueue")
    public void emailQueueListener(Email email){
        service.submit(new Runnable() {
            @Override
            public void run() {
                //发送邮件
                mailService.sendMailMsg(email);
            }
        });



    }
}
